package com.anycl.spring.web.controller;

import com.anycl.spring.web.dao.SpittleRepository;
import com.anycl.spring.web.service.SpittleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/spittles")
@Slf4j
public class SpittleController {

    @Autowired
    private SpittleService spittleService;

    // http://localhost:8080/spring/spittles?max=30
    @RequestMapping(method = RequestMethod.GET)
    public String spittles(Model model, @RequestParam Long max, @RequestParam(value = "num", defaultValue = "20") int count) {
        log.info("max: {}, count: {}", max, count);
        model.addAttribute("spittleList",spittleService.findAll());
        return "spittles";
    }

    @GetMapping("/{spittleId}")
    @ResponseBody
    public void show(@PathVariable("spittleId") Long spittleId) {
        log.info(spittleId.toString());
    }

}
